<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="net.groupme.gui.constants.VIEW_VOCABULARY"%>
<%@page import="net.groupme.gui.rendering.constants.RENDERING_CONSTANTS"%>
<%@page import="java.util.*"%>
<%@page import="net.groupme.model.*" %>
<%@page import="net.groupme.model.User"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	
	<% 
		String myHomeAction = "" + request.getAttribute(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW);
		if(myHomeAction == null){
			myHomeAction = request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW);
		}
		String subAction = "" + request.getAttribute(VIEW_VOCABULARY.PARAMETER_ACTION);
		if(subAction == null){
			subAction = request.getParameter(VIEW_VOCABULARY.PARAMETER_ACTION);
		}
	%>

	<!-- meta tags, link to css:  -->
	<%@ include file="./jsp-includes/mymetaheader.jsp" %>
	
	<!--  Ajax-Includes -->
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/interface/DWRUserManager.js'></script>
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/interface/DWRSearchManager.js'></script>
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/engine.js'></script>
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/util.js'></script>
    <script src="<%= request.getContextPath()%>/scriptaculous/prototype.js" type="text/javascript"></script>
	<script src="<%= request.getContextPath()%>/scriptaculous/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript" src="<%= request.getContextPath()%>/highslide/highslide.js"></script>

	<title>GroupMe! - The Social Semantic Web [Home]</title>
	<script type="text/javascript" language="javascript"><!--
	//<![CDATA[//>
		hs.graphicsDir = '<%= request.getContextPath()%>/highslide/graphics/';
	    hs.outlineType = 'rounded-white';
	    hs.outlineWhileAnimating = true;
	    hs.allowMultipleInstances = false;
	    hs.marginRight = 50;
	    
	    
	currentTab = 'latestGroups';
	
	function showTab(id){
		$(currentTab).hide();
		$(id).show();
		currentTab = id;
	}
	/**
      * Recomputes the User's Tag Cloud.
      */
     function computeTagCloud(){
     
     	$('tagCloudLoadingMessage').show();
     	<%if(VIEW_VOCABULARY.VIEW_MYTAGS.equals(myHomeAction)){
     		%>
     		DWRUserManager.getTagCloudForUser(null, null, showCompleteTagCloud);
     		<%}%>
     		DWRUserManager.getTopKTagCloudUser(null, null, 50, showTagCloud);
     }
   		
	/**
	 * Visualize a tag cloud.
	 */
	 function showTagCloud(tagCloud){
	 	$('tagCloudLoadingMessage').hide();
	 	if(tagCloud == null || tagCloud.html == ""){
	 		$('userTags').innerHTML = "<i>You haven't used any tags!</i>";
	 	}else{
	 		$('userTags').innerHTML =  tagCloud.html;
	 	}
	 }
	 
	 /**
	 * Visualize complete user tag cloud.
	 */
	 function showCompleteTagCloud(tagCloud){
	 	$('tagCloudLoadingMessage').hide();
	 	$('tagcloudheader').innerHTML = "<div class=\"grouplistHead\" style=\"margin-top:1em; margin-bottom:1em;\"><h4>All tags you have used so far</h4></div>";
	 	if(tagCloud == null || tagCloud.html == ""){
	 		$('mainGroupwindow').innerHTML = "<i>You haven't used any tags!</i>";
	 	}else{
	 		$('mainGroupwindow').innerHTML =  tagCloud.html;
	 	}
	 }
	
	//init stuff:		
	function init() {
		DWRUtil.useLoadingMessage();
		computeTagCloud();  
	}
	//<!]]>
	//-->
	</script>
</head>
<body onload="init();">
	<script language="javascript" type="text/javascript"><!--
		if ("${redirect}" != "" && ${userManager.loggedIn}){
			window.location.href = '${redirect}';
		}
	//-->
    </script>

	<!-- title image, logo:  -->
	<div id="groupme_header">
		<%@ include file="./jsp-includes/groupme_header.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="./jsp-includes/groupme_menu.jsp" %>
	</div>
	<!-- content and sidebar -->
	<!-- Content: -->
	<div id="mycontent">
		<div id="main_home">
			<div class="ro_bw">
				<div class="lo_bw">
					<div class="ru_bw">
						<div class="lu_bw">
							<div id="user_groups">
								<div class="content_header" id="grouplist_header" style="padding-top: 2px">
									<small style="color: #006699;">
									<span id="my_home_header">
										Your GroupMe! Home
									</span> 
									</small>
								</div>
								<div class="generalContent">
									<c:choose>
										<c:when test="${userManager.loggedIn}">
										<c:set var="user" value="${userManager.user}"/>
											<div id="personal-menu">Menu: 
												<a href="<%=VIEW_VOCABULARY.RESTful_USER_URI_PATTERN + userManager.getUser().getUserName() %>" title="Your profile page...">you</a>
												| <a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_GROUPS %>" title="Groups you created...">your groups</a>
												| <a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_FAVOURITES %>" title="Groups you subscribed to...">your favorites</a>
												| <a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_DASHBOARD %>" title="View what happened with your stuff...">your dashboard</a>
												| <a href="<%=VIEW_VOCABULARY.RESTful_CREATE_NEW_GROUP %>" title="Create a new group...">create a new group</a>
												| <a href="<%= VIEW_VOCABULARY.RESTful_ACCOUNT %>" title="Modify your GroupMe! account...">account settings</a> 
											</div>
										<%
									
										%>	<div id="tagcloudheader"></div>
											<div id="mainGroupwindow">
												<%
												if((VIEW_VOCABULARY.VIEW_LATEST).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/groupme_latestgroups.jsp"%>	
												<%}else if((VIEW_VOCABULARY.VIEW_SUBSCRIPTIONS).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/groupme_mysubscriptions.jsp"%>
												<%}else if((VIEW_VOCABULARY.VIEW_DASHBOARD).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/dashboard.jsp"%>
												<% } else if((VIEW_VOCABULARY.VIEW_MYSEARCH).equals(myHomeAction) ||
														(VIEW_VOCABULARY.VIEW_SEARCH_RESULT).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/groupme_mysearchresult.jsp"%>			
												<%}else if((VIEW_VOCABULARY.VIEW_CREATE_NEW_GROUP).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/createNewGroup.jsp"%>			
												<%}else if(VIEW_VOCABULARY.MYGROUPME_QUEUE_MOVE_RESOURCE.equals(subAction)){ %>
													<%@include file="./jsp-includes/addResourceFromQueue.jsp"%>			
												<%}else if((VIEW_VOCABULARY.VIEW_MYRESOURCE_QUEUE).equals(myHomeAction)){ %>
													<%@include file="./jsp-includes/resourcequeue.jsp"%>			
												<%}else if(VIEW_VOCABULARY.VIEW_MYTAGS.equals(myHomeAction)){%>
													<img src="<%= request.getContextPath() + RENDERING_CONSTANTS.RELATIVE_PATH_OF_AJAX_LOADING_IMAGE %>" alt="loading"/> 
													<small><i>loading tag cloud</i></small>
												<%}else{ %>			
													<%@include file="./jsp-includes/groupme_mygroups.jsp"%>	
												<%}%>
											</div>
											<br style="clear:right;" />
				
	 									</c:when>
										<c:otherwise>
											
											<p style="font-size: 0.8em;"><strong>Please login first!</strong> <br />
											You do not have a GroupMe! account yet? Then quickly create one: 
												<a href="<%= VIEW_VOCABULARY.ACTION_REGISTRATION %>" title="Create a GroupMe! account">create account</a>
											</p>
											<p style="font-size: 0.8em; margin-top:0.5em;"><strong>Login:</strong></p>
											<%@ include file="./jsp-includes/login.jsp" %>
										</c:otherwise>
									</c:choose>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		
		</div>
		
		<div id="sidebar_right">
		<c:if test="${userManager.loggedIn}">
			<div id="latestUsers">
				<div class="ro_bw">
					<div class="lo_bw">
						<div class="ru_bw">
							<div class="lu_bw">
								<div id="latest_facts">
									<div class="content_header" style="color: #006699; font-size: small; padding-top: 2px;" >
										Your 3 latest...
									</div>
									<div class="generalContent">
  										<div style="font-size:small;">
  										  	<c:if test="${!userManager.queueOfUserEmpty}">										
  										  		<div id="resourceQueue" style="margin-bottom: 1em;">
  										  			<strong ><a href="<%= VIEW_VOCABULARY.RESTful_MyGroupMe_QUEUE %>">Resource Queue</a></strong>
  										  			<div id="resourceQueueList" style="margin-top: 0.5em; padding-left:0.5em;">
  										  			<c:forEach items="${userManager.latestResourcesOfQueue}" var="resource">
														<a href="<%= request.getContextPath() + "/" +  VIEW_VOCABULARY.ACTION_HOME + "?" + VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW + "=" + VIEW_VOCABULARY.VIEW_ADD_RESOURCE_FROM_MYRESOURCE_QUEUE_TO_A_GROUP + "&" + VIEW_VOCABULARY.PARAMETER_ID + "=" %><c:out value="${resource.id}"/>" title="Add resource to group(s)"><c:out value="${resource.name}"/></a><br/>
														<c:out value="${resource.description}"/><br/>
													</c:forEach>
  										  			</div>
  										  		</div>
  										  	</c:if>
  											<div id="latestGroups" style="margin-bottom: 1em;">
  												<strong ><a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_GROUPS %>">Groups</a></strong>
  												<div id="latestGroupsList" style="margin-top: 0.5em; padding-left:1em;">
  												
  													<%
  													if(userManager.getLatestCreatedGroupsOfUser().size() == 0){
  														out.println("- You have no groups yet -");
  													}
  													else {
  													%>
  													<c:forEach items="${userManager.latestCreatedGroupsOfUser}" var="group">	
														<c:if test="${group.type != 'queue'}">
															<p id="latestGroup_<c:out value="${group.id}"/>"><a href="<c:out value="${group.URL}"/>"><c:out value="${group.name}"/></a></p>
														</c:if>
													</c:forEach>
													<%} %>
  										  		</div>
  											</div>
  											<!--
											<div id="personalGroups2" class="smallGrouplist">
											<div class="smallGrouplistHead">
												Your most visited Groups
											</div>
											- coming soon -
											<div class="smallGrouplistFooter"><a target="_blank" href="./">more... </a></div>
											</div>
											-->	
  											<div id="latestSubscibs" style="margin-bottom: 1em;">
  												<strong ><a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_FAVOURITES %>">Favorites</a></strong>
  												<div id="latestSubscibsList" style="margin-top: 0.5em; padding-left:1em;">
  													<c:if test="${!userManager.subscriber}">- You have no favorites -</c:if>
													<c:forEach items="${userManager.latestSubscribedGroupsOfUser}" var="group" varStatus="status">	
														<a href="<c:out value="${group.URL}"/>"><c:out value="${group.name}"/></a><br/>
													</c:forEach>
  										  		</div>
  											</div>
  											<%! 
  											
  											public String getShortNameForm(String name){
  												
  												if(name.length() > 17){
  													String shortName = name.substring(0, 14) + "...";
  													return shortName;
  												}
  												else{
  													return name;
  												}
  											}
  											
  											%>
  											
  											<div id="latestDashNews" style="margin-bottom: 1em;">
  												<strong ><a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_DASHBOARD %>">Dashboard News</a></strong>
  												<div id="latestDashNewsList" style="margin-top: 0.5em; padding-left:1em;">
  												<% 	List<DashboardAnnouncement> ann = userManager.getLatest3DashboardAnnouncements(); %>
												<% 	Iterator<DashboardAnnouncement> it = ann.iterator(); %>
												<% 	DashboardAnnouncement da = new DashboardAnnouncement(); 
													if(!it.hasNext()){%>
													- No news for you yet -
												<% 	}
													while (it.hasNext()) { 
														da = it.next(); %>
														<% if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_CREATED.equals(da.getAction())){%>
														
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_DELETED.equals(da.getAction())){%>
														Group <%=da.getGroupName()%> deleted.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_SUBSCRIBED.equals(da.getAction())){
															//TODO: anstatt ObjectFactory einzusetzen lieber den Subscriber-Username in da unterbringen
															User subscriber = ObjectFactory.getUser(da.getUserId());
														%>
														
														User <a href="<%= subscriber.getURI() %>"><%=subscriber.getUserName() %></a> subscribed to your 
														Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>" title="<%=da.getGroupName()%>"><%=getShortNameForm(da.getGroupName())%></a>.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_UNSUBSCRIBED.equals(da.getAction())){
															User subscriber = ObjectFactory.getUser(da.getUserId());
														%>
														
														User <a href="<%= subscriber.getURI() %>"><%= subscriber.getUserName() %></a> unsubscribed your
														Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>" title="<%=da.getGroupName()%>"><%=getShortNameForm(da.getGroupName())%></a>.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_TAGGED.equals(da.getAction())){%>
														
														Your <%if (MODEL_CONSTANTS.ROLE_SUBSCRIBER.equals(da.getRole())){ %> subscribed <%} %> 
														Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>" title="<%=da.getGroupName()%>"><%=getShortNameForm(da.getGroupName())%></a>
														was tagged.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_CREATED.equals(da.getAction())){%>
														
														A new Resource: <a href="<%= da.getResourceURI()%>" title="<%=da.getResourceName() %>"><%=getShortNameForm(da.getResourceName())%></a> was added to your subscribed
														Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>"  title="<%=da.getGroupName()%>"><%=getShortNameForm(da.getGroupName())%></a>.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_REMOVED.equals(da.getAction())){%>
														
														The Resource: <a href="<%=  da.getResourceURI()%>"  title="<%=da.getResourceName() %>"><%=getShortNameForm(da.getResourceName())%></a> was removed from your subscribed
														Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>" title="<%=da.getGroupName() %>"><%=getShortNameForm(da.getGroupName())%></a>.
														
														<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_TAGGED.equals(da.getAction())){%>
														
														The Resource: <a href="<%=  da.getResourceURI()%>" title="<%=da.getResourceName() %>"><%=getShortNameForm(da.getResourceName())%></a> in your 
														
														<%if (MODEL_CONSTANTS.ROLE_SUBSCRIBER.equals(da.getRole())){ %> subscribed <%} %> Group: <a href="<%=VIEW_VOCABULARY.RESTful_GROUP_URI_PATTERN %><%=da.getGroupId()%>"  title="<%=da.getGroupName()%>"><%=getShortNameForm(da.getGroupName())%></a>
														was tagged.
														<%}
														%>
														<br />
														<span style="color:gray;font-size:0.8em;"><%=da.getDate().substring(0,11)%></span>
														<%
														if(it.hasNext()) {%><br/><br/><%} %>
												<%}  %>
  										  		</div>
  											</div>
  										</div>
									</div>
									<div>
									</div>
								</div>
							</div>	
						</div>
					</div>
				</div>
			</div>
			</c:if>
			
			
			
			<c:if test="${userManager.loggedIn}">
			<div id="tagCloud">
				<div class="ro_bw">
					<div class="lo_bw">
						<div class="ru_bw">
							<div class="lu_bw">
								<div id="user_tagCloud" style="color: #006699; font-size: small; padding-top: 2px; min-height: 30px;">
									<div class="content_header">
										Your top 50 tags [<a href="<%=VIEW_VOCABULARY.RESTful_MyGroupMe_TAGS %>" title="Show all tags...">show all tags</a>]
									</div>
									
									
										<div id="userTags" class="generalContent">
										
										</div>
										<span id="tagCloudLoadingMessage">
											<img src="<%= request.getContextPath() + RENDERING_CONSTANTS.RELATIVE_PATH_OF_AJAX_LOADING_IMAGE %>" alt="loading"/> 
											<small><i>refreshing tag cloud</i></small>
										</span>
									
								</div>
							</div>	
						</div>
					</div>
				</div>
			</div>
			</c:if>
			
		</div>
	</div>
	
	<div id="footer">
		<%@ include file="./jsp-includes/footer.jsp" %>
	</div>
</body>
</html>